package me.ctidy.assignment04.activity.assets;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import me.ctidy.assignment04.R;
import me.ctidy.assignment04.entity.Assets;

/**
 * AssetsDetailActivity
 *
 * @author ctidy
 */
public class AssetsDetailActivity extends AppCompatActivity {

    private EditText etAssetsName, etAssetsMoney, etAssetsRemarks;
    private Spinner spinnerAssetsType;
    private Button btnDel, btnModify;

    private String assetsType;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_assets_detail);
        initUI();
    }

    private void initUI() {
        // I. 绑定控件
        etAssetsName = findViewById(R.id.aad_et_assets_name);
        etAssetsMoney = findViewById(R.id.aad_et_assets_money);
        etAssetsRemarks = findViewById(R.id.aad_et_assets_remarks);
        spinnerAssetsType = findViewById(R.id.aad_spinner_assets_type);
        btnDel = findViewById(R.id.aad_btn_del);
        btnModify = findViewById(R.id.aad_btn_modify);

        // II. 获取数据
        Assets assets = (Assets) getIntent().getSerializableExtra("assets");

        // III. 渲染数据
        etAssetsName.setText(assets.getAssetsName());
        etAssetsMoney.setText(String.valueOf(assets.getAssetsMoney()));
        etAssetsRemarks.setText(assets.getRemarks());
        spinnerAssetsType.setSelection(assets.getAssetsType().getId().intValue() - 1);

        // IV. 注册监听器并绑定
        spinnerAssetsType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                assetsType = spinnerAssetsType.getSelectedItem().toString();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        //TODO 动态数据

    }
}
